package rmy.service.impl;


import onbon.bx06.Bx6GEnv;
import onbon.bx06.Bx6GException;
import onbon.bx06.Bx6GScreenClient;
import onbon.bx06.area.TextCaptionBxArea;
import onbon.bx06.file.ProgramBxFile;
import onbon.bx06.series.Bx6E;
import onbon.bx06.utils.DisplayStyleFactory;
import rmy.device.onbon.*;
import rmy.domain.VoicCmd;
import rmy.domain.VoicParam;
import rmy.service.VoicInterface;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;

public class OnbonBx06VoicDevice implements VoicInterface {


    @Override
    public boolean sendVoic(String strIp, int nPort, VoicParam compParam, VoicCmd voicCmd) throws Exception {
        Bx6GEnv.initial(30000);
        Bx6GScreenClient screen = new Bx6GScreenClient( "voicScreen",new Bx6E() );
        if (!screen.connect(strIp, nPort)) {
            throw new Exception("connect " + strIp + ":" + nPort + " failed!!!");
        }

//        DisplayStyleFactory.DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyleFactory.DisplayStyle[0]);

        ProgramBxFile pf = new ProgramBxFile( "P000",screen.getProfile() );

        // 语音部分
        TextCaptionBxArea area_sound = new TextCaptionBxArea( 0,0,160,16,screen.getProfile());
        area_sound.setVoiceContent(voicCmd.getSound_content());// 该字符串会被语音播报
        area_sound.setVoiceFlag(true);
        area_sound.setVoiceReplayTimes(voicCmd.getSound_repeat());// 设置重复播报3次，如果不设置，默认一直播报
        area_sound.setVoicePerson(voicCmd.getSound_person());
        area_sound.setVoiceSpeed(voicCmd.getSound_speed());
        area_sound.setVoiceVolume(voicCmd.getSound_volume());
        pf.addArea(area_sound);
//
//        // 清除之前的节目
//        screen.deletePrograms();
//        screen.deleteAllDynamic();

        screen.writeProgram(pf);

        screen.disconnect();
        return true;
    }
}
